package com.cbs.android.module.userkit.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.cbs.android.component.application.activity.CBSActivity;
import com.cbs.android.component.binaryutils.BinaryUtils;
import com.cbs.android.module.user.user.UserModule;
import com.cbs.android.module.user.user.entity.User;
import com.cbs.android.module.userkit.R;
import com.cbs.android.module.userkit.UserKit;

import net.glxn.qrgen.android.QRCode;

/**
 * Created by zyj on 2016/3/25.
 */
public class QrCodeActivity extends CBSActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.cbs_userkit_activity_qrcode);

        User user = UserModule.getUser();
        if (user == null) {
            Intent intent = new Intent();
            intent.putExtra(UserKit.IntentMessage, getString(R.string.cbs_userkit_verify_unregistered));
            setResult(RESULT_CANCELED, intent);
            finish();
            return;
        }
        findViewById(R.id.cbs_userkit_qrcode_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        ImageView imageView = (ImageView) findViewById(R.id.cbs_userkit_qrcode_code);
        String id = new String(BinaryUtils.base64Encode(String.valueOf(UserModule.getUser().getId()).getBytes()));

        imageView.setImageBitmap(QRCode.from("user://" + id).withCharset("utf-8").bitmap());
    }
}
